package offer.binarytree;


import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
 * Description：
 * Author: zhangc
 * Date：2017/7/20 20:49
 */
public class LevelOrder23 {

    public static <T> List<T> levelOrder(BinaryTree<T> head) {
        if (head == null)
            return null;
        Queue<BinaryTree<T>> queue = new LinkedList<>();
        List<T> list = new ArrayList<>();
        queue.add(head);
        BinaryTree<T> temp = null;
        while (!queue.isEmpty()) {
            temp = queue.remove();
            list.add(temp.value);
            if (temp.left != null)
                queue.add(temp.left);
            if (temp.right != null)
                queue.add(temp.right);
        }
        return list;
    }

}
